package com.li.config;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class BloomFilterInit {
    @Resource
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void init(){
        //白名单customer加载到布隆过滤器
        String key = "customer:12";
        //计算hashcode ,取绝对值
        int hashValue =Math.abs(key.hashCode());
        //通过hashValue 和2的32次方取余
        long index =(long)(hashValue % Math.pow(2,32));
        log.info(key+"对应的坑位index:{}",index);
        //设置redis里面bitmap对应类型的坑位,并将该值设置为1
        redisTemplate.opsForValue().setBit("whitelistCustomer",index,true);
    }
}
